const express = require("express");
let createDBconnect = require("../db/createDBconnect.js");
const router = express.Router();


//登陆请求
router.get("/login", (req, res) => {
  try {
    const connect = createDBconnect();
    let sqlQuery = `select * from users where userid='${req.query.userid}'`
    console.log(req.query.password)
    connect.query(sqlQuery, function (err, result) {
      if (err) {
        console.log(`SQL error: ${err}!`);
      } else {
        // console.log(result);
        if(result[0].password == req.query.password)
        {
          res.status(201).send({data: result[0],status: 201});
        }
        else{
          res.send({status: 202});
        }
      }
    });
    connect.end();
  } catch (err) {
    console.log(err);
    return ;
  }
});



module.exports = router;
